package com.travel.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.travel.common.pojo.RouteCustom;
import com.travel.common.pojo.relationUser;
import com.travel.service.RouteService;


@Controller
@RequestMapping("route")
public class RouteController {
	@Autowired
	private RouteService rs;
	
	public static Logger logger = LoggerFactory.getLogger(RouteCustom.class); 
	
	
	//查询线路详细信息
	@RequestMapping("/routeList")
	public String  routeList(ModelMap map) {
		map.put("routeList", rs.selectRouteList());
		return "routeList";
	}
	//跳转到新增页面
	@RequestMapping("/addRoute")
	public String addRoute(ModelMap map) {
		//下拉菜单选择优惠活动
		map.put("discountList", rs.selectDisCountList());
		//下拉菜单选择负责人
		map.put("relationUserList", rs.selectrelationUserList());
		//下拉菜单选择创建人
		map.put("userList", rs.selectUserList());
		//使form表单绑定RouteCustom
		map.put("rc", new RouteCustom());
		return "route-input";
	}
	//保存线路
	@RequestMapping("/saveRoute")
	@ResponseBody
	public Integer saveRoute(RouteCustom rc) {
		logger.debug("进入saveRoute");
		Integer i=rs.saveRoute(rc);
		Integer j=0;
		if(i==1) {
			Integer relationUserId = rc.getRelationUserId();
			relationUser relationUser = rs.selectrelationUserById(relationUserId);
			j=rs.updateRouteByRelation(relationUser,rc.getId());
		}
		return j;
	}
}
